//
//  AcvWallViewController.m
//  ZiJinLian
//
//  Created by 震霄 张 on 2018/4/5.
//  Copyright © 2018年 lzy. All rights reserved.
//

#import "AcvWallViewController.h"
#import "AcWallCollectionViewCell.h"
#import "ActivityWallListModel.h"
#import "AcvChoosePosController.h"
@interface AcvWallViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)NSMutableArray *dataArr;
@end

@implementation AcvWallViewController
static NSString *const ZXActivityWallCellID = @"ZXActivityWallCell";

-(NSMutableArray *)dataArr
{
	if (_dataArr == nil) {
		_dataArr = [NSMutableArray array];
	}
	return _dataArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
	self.navigationItem.title = @"活动墙";
	[self setupUI];
}

-(void)viewWillAppear:(BOOL)animated
{
	[super viewWillAppear:animated];
	[self setupDataWithID:self.ID];
}

-(void)setupDataWithID:(NSInteger)ID
{
	NSMutableDictionary *dic=[[NSMutableDictionary   alloc]init];
	dic[@"id"]=[NSString stringWithFormat:@"%ld",ID];
	[self doHttpRequestWithApi:API_ACTWALL_LIST method:GET dic:dic successBlock:^(NSDictionary *dic) {
		NSLog(@"%@",dic);
		if ([dic[@"status"] integerValue] == 0) {
			self.dataArr = [ActivityWallListModel mj_objectArrayWithKeyValuesArray:dic[@"data"]];
			[self.collectionView reloadData];
		}else{
			[MBProgressHUD showError:dic[@"msg"]];

		}
	}];
	
	
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)setupUI
{
	self.view.backgroundColor = [UIColor whiteColor];
	[self.view addSubview:self.collectionView];
}
- (UICollectionView *)collectionView
{
	if (!_collectionView) {
		UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
		//设置滚动方向
		[flowlayout setScrollDirection:UICollectionViewScrollDirectionVertical];
		//左右间距
		flowlayout.minimumInteritemSpacing =5;
		//上下间距
		flowlayout.minimumLineSpacing = 8;
//		[flowlayout setHeaderReferenceSize:CGSizeMake(MainW,270+MainW/3)];
		_collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, MainW, MainH-RD_NavBarHeight) collectionViewLayout:flowlayout];
		_collectionView.backgroundColor = Gray_Color;
		_collectionView.delegate = self;
		_collectionView.dataSource = self;
		_collectionView.showsVerticalScrollIndicator = NO;
		_collectionView.showsHorizontalScrollIndicator = NO;
		
		[_collectionView registerNib:[UINib nibWithNibName:@"AcWallCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:ZXActivityWallCellID];
//		[_collectionView registerClass:[WarkCollectionHeadView class]
//			forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
//				   withReuseIdentifier:@"WarkCollectionHeadView"];
		//_collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreTopic)];
		
	}
	return _collectionView;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
	return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
	return self.dataArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
	AcWallCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:ZXActivityWallCellID forIndexPath:indexPath];
	cell.model = self.dataArr[indexPath.row];
	return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
	NSLog(@"select");
	AcvChoosePosController *vc = [[AcvChoosePosController alloc]init];
	vc.ID = self.ID;
	[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
	return CGSizeMake((MainW-15)/2, (MainW-15)/2+60);
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
	return UIEdgeInsetsMake(5, 5, 5, 5);//分别为上、左、下、右
}

@end
